#Bibliotecas de análise de dados
import pandas as pd
import numpy as np
# Bibliotecas gráficas
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
from plotly.subplots import make_subplots
from matplotlib import pyplot as plt
from pandas_profiling import ProfileReport
#Configurações de output do Notebook
pd.set_option('display.float_format', lambda x: '%.3f' % x)
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', 8)
def configure_plotly_browser_state():
import IPython
display(IPython.core.display.HTML('''
<script src="/static/components/requirejs/require.js"></script>
<script>
requirejs.config({
paths: {
base: '/static/base',
plotly: 'https://cdn.plot.ly/plotly-2.12.1.min.js',
},
});
</script>
'''))
import IPython
def configure_plotly_browser_state():
display(IPython.core.display.HTML('''
<script src="/static/components/requirejs/require.js"></script>
<script>
requirejs.config({
paths: {
base: '/static/base',
plotly: 'https://cdn.plot.ly/plotly-2.12.1.min.js',
},
});
</script>
'''))
IPython.get_ipython().events.register('pre_run_cell', configure_plotly_browser_state)
%%HTML
<script src="https://cdn.plot.ly/plotly-2.12.1.min.js"></script>
database = pd.read_excel(r'C:\Users\joaow.000\Downloads\Violence-Project-Mass-Shooter-Database-Version-5-May-20221.xlsx',
sheet_name = 'Full Database', header=[1])
codebook = pd.read_excel(r'C:\Users\joaow.000\Downloads\Violence-Project-Mass-Shooter-Database-Version-5-May-20221.xlsx',
sheet_name = 'Codebook')
database
| Case # | Shooter Last Name | Shooter First Name | Full Date | Day of Week | Day | Month | Year | Shooting Location Address | City | Count State | State | State Code | Region | Urban/Suburban/Rural | Location | Insider/Outsider | Insider / Outsider | Workplace shooting | Multiple Locations | Other Location | Armed Person on Scene | Specify Armed Person | teste | Attacks by year | Numbers by year | Numbers by state | Number Killed | Number Injured | Family Member Victim | Romantic Partner Victim | Kidnapping or Hostage Situation | Age | Genero | Gender | race | Race | imigrante | Immigrant | orientacao | Sexual Orientation | religiao | Religion | Education | performance | School Performance | School Performance Specified | ordem | Birth Order | Number of Siblings | Older Siblings | Younger Siblings | relacionamento | Relationship Status | filhos | Children | emprego | Employment Status | Employment Type | Military Service | Military Branch | Community Involvement | Community Involvement Specified | fbi | Known to Police or FBI | ficha | Criminal Record | Part I Crimes | Part II Crimes | Highest Level of Criminal Justice Involvement | alteracao fisica | History of Physical Altercations | History of Animal Abuse | History of Domestic Abuse | Domestic Abuse Specified | History of Sexual Offenses | Gang Affiliation | Terror Group Affiliation | hate group | Known Hate Group or Chat Room Affiliation | games | Violent Video Games | praticava bullying | Bully | sofria bullying | Bullied | pais solteiros | Raised by Single Parent | divorcio | Parental Divorce / Separation | morte parental | Parental Death in Childhood | Parental Suicide | trauma | Childhood Trauma | abusado fisicamente | Physically Abused | abusado sexualmente | Sexually Abused | emocionalmente abusado | Emotionally Abused | Neglected | socioeconomico | Childhood SES | mae sofria violencia | Mother Violent Treatment | abuso substancia | Parental Substance Abuse | ficha pais | Parent Criminal Record | Family Member Incarcerated | Adult Trauma | Recent or Ongoing Stressor | Signs of Being in Crisis | Timeline of Signs of Crisis | Signs of Crisis Expanded | Inability to Perform Daily Tasks | Notably Depressed Mood | Unusually Calm or Happy | Rapid Mood Swings | Increased Agitation | Abusive Behavior | Isolation | Losing Touch with Reality | Paranoia | Suicidality | Prior Hospitalization | Voluntary or Involuntary Hospitalization | Prior Counseling | Voluntary or Mandatory Counseling | Psychiatric Medication | Psychiatric Medication Specified | Treatment 6 Months Prior to Shooting | Mental Illness | Known Family Mental Health History | Autism Spectrum | Substance Use | Health Issues | Health Issues - Specify | Head Injury / Possible TBI | Known Prejudices | Motive: Racism/Xenophobia | Motive: Religious Hate | Motive: Misogyny | Motive: Homophobia | Motive: Employment Issue | Motive: Economic Issue | Motive: Legal Issue | Motive: Relationship Issue | Motive: Interpersonal Conflict | Motive: Fame-Seeking | Motive: Other | Motive: Unknown | Role of Psychosis in the Shooting | Social Media Use | Leakage | Leakage How | Leakage Who | Leakage Specific/Nonspecific | Interest in Past Mass Violence | Relationship with Other Shooting(s) | Specify Relationship to Other Shooting(s) | Legacy Token | Pop Culture Connection | Specify Pop Culture Connection | Planning | Performance | Interest in Firearms | Firearm Proficiency | Total Firearms Brought to the Scene | Other Weapons or Gear | Specify Other Weapons or Gear | On-Scene Outcome | Attempt to Flee | Insanity Defense | Criminal Sentence | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Whitman | Charles | 1966-08-01 | Monday | 1 | 8 | 1966 | 110 Inner Campus Drive, Austin, TX 78705 | Austin | 19 | TX | 43 | 0 | 0 | 1 | Insider | 1 | 0 | 1 | 7.000 | 1 | 2.000 | 1 | 2 | 20 | 180 | 15 | 31 | 1.000 | 1.000 | 0 | 25.000 | Male | 0.000 | White | 0.000 | Not Immigrant | 0.000 | Heterosexual | 0.000 | Christian | 1.000 | 2.000 | NaN | 0.000 | 1.9 GPA | Oldest Child | 1.000 | 2.000 | 0.000 | 2.000 | Married | 2.000 | No evidence | 0.000 | Not Working | 0.000 | NaN | 1.000 | 3.000 | 3.000 | formerly an altar boy and Eagle Scout | No evidence | 0.000 | Yes | 1.000 | 0 | 9 | 4.000 | No evidence | 0.000 | 0.000 | 1.000 | 1 | 0.000 | 0.000 | 0.000 | No evidence | 0.000 | NA (pre-1992) | 3.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | Yes | 1.000 | Yes | 1.000 | No evidence | 0.000 | Yes | 1.000 | 0.000 | Middle Class | 1.000 | Yes | 1.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | 6 | 4 | 1.000 | 2.000 | A few months before the shooting, he saw a psy... | 1.000 | 1.000 | 0.000 | 1.000 | 1.000 | 0.000 | 0.000 | 0.000 | 0.000 | 2.000 | 0.000 | 0.000 | 1.000 | 1 | 0.000 | NaN | 1.000 | 1 | 0 | 0.000 | 3 | 1.000 | brain tumor | 0.000 | 0 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 2.000 | 1.000 | 0 | 0 | 1 | 0.000 | 1.000 | Robert Smith killed 5 people a few months afte... | 1.000 | 0.000 | NaN | 1.000 | 0.000 | 1.000 | 3.000 | 7.000 | 1.000 | hatchet, hammer, knives, wrench, ropes, water,... | 1.000 | 0.000 | 2.000 | 0.000 |
| 1 | 2 | Smith | Robert | 1966-11-12 | Saturday | 12 | 11 | 1966 | Rose-Mar College of Beauty in Mesa, AZ | Mesa | 3 | AZ | 3 | 3 | 0 | 4 | Outsider | 0 | 0 | 0 | NaN | 0 | 0.000 | 1 | 2 | 20 | 15 | 5 | 2 | 0.000 | 0.000 | 0 | 18.000 | Male | 0.000 | White | 0.000 | Not Immigrant | 0.000 | Heterosexual | 0.000 | Don't Have | 0.000 | 0.000 | NaN | 2.000 | good grades, on student council | Oldest Child | 1.000 | 1.000 | 0.000 | 1.000 | Single | 0.000 | No evidence | 0.000 | Not Working | 0.000 | NaN | 0.000 | NaN | 0.000 | NaN | No evidence | 0.000 | No evidence | 0.000 | 0 | 0 | 0.000 | No evidence | 0.000 | 0.000 | 0.000 | 0 | 0.000 | 0.000 | 0.000 | No evidence | 0.000 | NA (pre-1992) | 3.000 | No evidence | 0.000 | Yes | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | Yes | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | Middle Class | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | 0 | 0 | 1.000 | 3.000 | A few years before the shooting, he became obs... | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 0 | 0.000 | NaN | 0.000 | 2 | 0 | 0.000 | 0 | 0.000 | NaN | 0.000 | 2, 4 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 2.000 | 0.000 | NaN | NaN | NaN | 1.000 | 1.000 | Happened a few months after the Charles Whitma... | 0.000 | 0.000 | NaN | 1.000 | 1.000 | 0.000 | 1.000 | 1.000 | 1.000 | knife, nylon cord | 2.000 | 0.000 | 1.000 | 1.000 |
| 2 | 3 | Held | Leo | 1967-10-23 | Monday | 23 | 10 | 1967 | 599 South Highland Street Lockhaven, PA 17745 | Lock Haven | 9 | PA | 38 | 2 | 2 | 9 | Insider | 1 | 1 | 1 | 7.000 | 0 | 0.000 | 1 | 1 | 6 | 48 | 6 | 6 | 0.000 | 0.000 | 0 | 39.000 | Male | 0.000 | White | 0.000 | Not Immigrant | 0.000 | Heterosexual | 0.000 | Christian | 1.000 | 2.000 | NaN | NaN | NaN | NaN | NaN | 2.000 | NaN | NaN | Married | 2.000 | Yes | 1.000 | Working | 1.000 | 2.000 | 1.000 | 0.000 | 2.000 | school board member, director of the local Boy... | Yes | 1.000 | No evidence | 0.000 | 0 | 1 | 1.000 | Yes | 1.000 | 0.000 | 0.000 | 0 | 0.000 | 0.000 | 0.000 | No evidence | 0.000 | NA (pre-1992) | 3.000 | No evidence | 0.000 | Yes | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | Middle Class | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | 0 | 2 | 1.000 | 2.000 | He stopped talking to his friends in the month... | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 1.000 | 1.000 | 1.000 | 2.000 | 0.000 | 0.000 | 0.000 | 0 | 0.000 | NaN | 0.000 | 4 | 0 | 0.000 | 0 | 0.000 | NaN | 0.000 | 0 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 1.000 | 2.000 | 0.000 | NaN | NaN | NaN | 0.000 | 0.000 | NaN | 0.000 | 0.000 | NaN | 0.000 | 0.000 | 1.000 | 3.000 | 2.000 | 1.000 | holster | 1.000 | 0.000 | 2.000 | 0.000 |
| 3 | 4 | Pearson | Eric | 1968-03-16 | Saturday | 16 | 3 | 1968 | 11703 Lake Rd, Ironwood, MI 49938 | Ironwood | 5 | MI | 22 | 0 | 2 | 5 | Outsider | 0 | 0 | 1 | 7.000 | 0 | 0.000 | 1 | 1 | 7 | 25 | 7 | 2 | 0.000 | 0.000 | 0 | 56.000 | Male | 0.000 | White | 0.000 | Not Immigrant | 0.000 | Heterosexual | 0.000 | Unknown | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Single | 0.000 | No evidence | 0.000 | Working | 1.000 | 0.000 | 0.000 | NaN | 0.000 | NaN | No evidence | 0.000 | No evidence | 0.000 | 0 | 0 | 0.000 | No evidence | 0.000 | 0.000 | 0.000 | 0 | 0.000 | 0.000 | 0.000 | No evidence | 0.000 | NA (pre-1992) | 3.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | No Info | NaN | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | 0 | 1 | 0.000 | NaN | NaN | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0 | 0.000 | NaN | 0.000 | 0 | 0 | 0.000 | 1 | 0.000 | NaN | 0.000 | 0 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 2.000 | 0.000 | NaN | NaN | NaN | 0.000 | 0.000 | NaN | 0.000 | 0.000 | NaN | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | NaN | 2.000 | 0.000 | 0.000 | 3.000 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 176 | 178 | Gaxiola Gonzalez | Aminadab | 2021-03-31 | Wednesday | 31 | 3 | 2021 | 202 West Lincoln Avenue Orange, CA 92865 | Orange | 28 | CA | 5 | 3 | 1 | 6 | Insider | 1 | 1 | 0 | NaN | 0 | 0.000 | 1 | 6 | 43 | 192 | 4 | 1 | 0.000 | 0.000 | 0 | 44.000 | Male | 0.000 | Latinx | 2.000 | Not Immigrant | 0.000 | Heterosexual | 0.000 | Unknown | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | Divorced/separated/widowed | 3.000 | Yes | 1.000 | Working | 1.000 | 0.000 | 0.000 | NaN | NaN | NaN | No evidence | 0.000 | Yes | 1.000 | 4 | 1, 9 | 4.000 | No evidence | 0.000 | 0.000 | 2.000 | 1, 4 | 0.000 | 0.000 | 0.000 | No evidence | 0.000 | No Evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | No Info | NaN | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | 0 | 0 | 0.000 | NaN | NaN | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0 | 0.000 | 0 | 0.000 | 0 | 0 | 0.000 | 0 | 0.000 | 0 | 0.000 | 0 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | NaN | NaN | NaN | 0.000 | 0.000 | NaN | 0.000 | 0.000 | NaN | 1.000 | 0.000 | 0.000 | 0.000 | 1.000 | 1.000 | pepper spray, handcuffs, ammunition, locked ex... | 2.000 | 0.000 | 3.000 | NaN |
| 177 | 179 | Hole | Brandon Scott | 2021-04-15 | Thursday | 15 | 4 | 2021 | 8951 Mirabel Rd, Indianapolis, IN 46241 | Indianapolis | 2 | IN | 14 | 1 | 0 | 9 | Insider | 1 | 1 | 0 | NaN | 0 | 0.000 | 1 | 6 | 43 | 12 | 8 | 7 | 0.000 | 0.000 | 0 | 19.000 | Male | 0.000 | White | 0.000 | Not Immigrant | 0.000 | Heterosexual | 0.000 | Unknown | NaN | 0.000 | NaN | NaN | NaN | Youngest Child | 3.000 | 1.000 | 1.000 | 0.000 | Single | 0.000 | No evidence | 0.000 | Not Working | 0.000 | 0.000 | 0.000 | NaN | 0.000 | NaN | Yes | 1.000 | Yes | 1.000 | 4 | 1 | 4.000 | No evidence | 0.000 | 0.000 | 1.000 | 1, 4 | 0.000 | 0.000 | 0.000 | Hate group community association | 1.000 | No Evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | Yes | 1.000 | No evidence | 0.000 | Yes | 1.000 | 1.000 | Yes | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | No Info | NaN | No evidence | 0.000 | Yes | 1.000 | No evidence | 0.000 | 0.000 | 0 | 2, 4 | 1.000 | 3.000 | Placed on a mental health hold in March 2020 a... | 0.000 | 1.000 | 1.000 | 0.000 | 0.000 | 1.000 | 1.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 1.000 | 1 | 1.000 | Lexapro, Intuniv | 0.000 | 1 | 1 | 0.000 | 0 | 0.000 | NaN | 0.000 | 1 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 1.000 | 0.000 | NaN | NaN | NaN | 0.000 | 0.000 | NaN | 1.000 | 2.000 | Less than 40 minutes before the shooting, he w... | 0.000 | 0.000 | 0.000 | 0.000 | 2.000 | 0.000 | NaN | 0.000 | 0.000 | 2.000 | NaN |
| 178 | 180 | Cassidy | Samuel | 2021-05-26 | Wednesday | 26 | 5 | 2021 | 101 W Younger Ave, San Jose, CA 95110 | San Jose | 28 | CA | 5 | 3 | 0 | 9 | Insider | 1 | 1 | 0 | NaN | 0 | NaN | 1 | 6 | 43 | 192 | 9 | 0 | 0.000 | 0.000 | 0 | 57.000 | Male | 0.000 | White | 0.000 | Not Immigrant | 0.000 | Heterosexual | 0.000 | Unknown | NaN | 2.000 | NaN | NaN | NaN | Oldest Child | 1.000 | 1.000 | 0.000 | 1.000 | Divorced/separated/widowed | 3.000 | No evidence | 0.000 | Not Working | 0.000 | 2.000 | 0.000 | NaN | 0.000 | NaN | No evidence | 0.000 | Yes | 1.000 | 2 | 9 | 3.000 | No evidence | 0.000 | 0.000 | 1.000 | 1, 2 | 1.000 | 0.000 | 0.000 | No evidence | 0.000 | No Evidence | 0.000 | Yes | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | No Info | NaN | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | 0 | 2 | 1.000 | 3.000 | His ex-wife reported that he hated his workpla... | 0.000 | 0.000 | 0.000 | 1.000 | 1.000 | 1.000 | 1.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 0 | 1.000 | unspecified | 0.000 | 1, 2 | 0 | 0.000 | 1 | 0.000 | NaN | 0.000 | 0 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0, 2 | 2, 9 | 0, 0 | 1.000 | 0.000 | NaN | 0.000 | 0.000 | NaN | 1.000 | 0.000 | 1.000 | 0.000 | 3.000 | 1.000 | 32 extended magazines | 0.000 | 0.000 | 2.000 | NaN |
| 179 | 181 | Crumbley | Ethan | 2021-11-30 | Tuesday | 30 | 11 | 2021 | 745 N Oxford Rd, Oxford, MI 48371 | Oxford | 5 | MI | 22 | 1 | 1 | 0 | Insider | 1 | 0 | 0 | NaN | 0 | NaN | 1 | 6 | 43 | 25 | 4 | 7 | 0.000 | 0.000 | 0 | 15.000 | Male | 0.000 | White | 0.000 | Not Immigrant | 0.000 | Heterosexual | 0.000 | Unknown | NaN | 0.000 | NaN | NaN | NaN | Youngest Child | 3.000 | 1.000 | 1.000 | 0.000 | Single | 0.000 | No evidence | 0.000 | Not Working | 0.000 | NaN | 0.000 | NaN | 0.000 | NaN | No evidence | 0.000 | No evidence | 0.000 | 0 | 0 | 0.000 | Yes | 1.000 | 1.000 | 0.000 | 0 | 0.000 | 0.000 | 0.000 | No evidence | 0.000 | Yes | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 0.000 | Yes | 1.000 | No evidence | 0.000 | No evidence | 0.000 | No evidence | 0.000 | 1.000 | Lower Class | 0.000 | No evidence | 0.000 | Yes | 1.000 | No evidence | 0.000 | 0.000 | 0 | 0 | 1.000 | 2.000 | In the months before the shooting, his only fr... | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0 | 0.000 | NaN | 0.000 | 4 | 0 | 0.000 | 0 | 0.000 | NaN | 0.000 | 0 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 0.000 | 1.000 | 0.000 | 1.000 | 1.000 | 5, 3, 4 | 7, 7, 9 | 1, 0, 0 | 1.000 | 0.000 | NaN | 0.000 | 0.000 | NaN | 1.000 | 0.000 | 1.000 | 1.000 | 1.000 | 0.000 | NaN | 2.000 | 0.000 | 3.000 | NaN |
180 rows × 176 columns
#profile = ProfileReport(database, html={'style':{'full_width':True}})
#profile.to_notebook_iframe()
#profile.to_file("your_report.html")
## "Normalizando"
normal_array = database['Numbers by year']/np.amax(database['Numbers by year'])
cor = px.colors.sample_colorscale(px.colors.sequential.dense, normal_array,
low=500000, high=5000, colortype='rgb')
ano = px.histogram(database, x='Year', nbins=60, color='Numbers by year',
color_discrete_sequence=cor)
ano.update_layout(showlegend=False)
ano.show()
state = px.scatter_geo(database, locations='State', scope='usa',
locationmode='USA-states', color= 'Numbers by state', size = 'Count State',
color_continuous_scale = 'Picnic', size_max=40, range_color = [0,180])
state.update_coloraxes(colorbar=dict(thickness=26, title="Total Deaths by State",
ticklen=1, tickcolor='black',
tickfont=dict(size=12, color='black')))
state.show()
politica = pd.read_excel(r'C:\Users\joaow.000\Downloads\teste.xlsx')
fig = px.choropleth(politica, locations = 'ABV', locationmode='USA-states', color='Republican', scope='usa')
fig.add_trace(go.Scattergeo(mode = 'markers', locations=database['State'],
locationmode = 'USA-states', marker=dict(size=database["Count State"], color='blue', sizeref = 0.4, ),
hoverinfo='text+name', text = database['Count State'], name='Total Cases'))
fig.update_layout(title_text='Numbers of Attacks by State', title_x=0.5)
fig.show()
celula = codebook.iloc[[18],2:13]
fig = go.Figure(data = go.Table(header=dict(values=list(["Primary location"])) ,cells = dict(values = celula)))
fig.show()
fig = px.treemap(database, path=['Insider/Outsider'], labels = ['Insider', 'Outsider'])
fig.show()
database1 = database.drop(database[database['Case #']=='145, 146'].index)
print('Média de Idade = ' , np.mean(database1['Age']))
print('Mediana de Idade =', np.median(database1['Age']) )
Média de Idade = 33.910614525139664 Mediana de Idade = 33.0
idade = px.histogram(database1, x= 'Age', nbins= 55, color = 'Genero' )
idade.show()
fig = px.sunburst(database1, path= ['race', 'orientacao','imigrante', 'religiao' ])
fig.update_traces(textinfo="label+percent entry")
fig.show()
figg = make_subplots(
rows=2, cols=2,
#subplot_titles=("Title 1", "Title 2"),
shared_xaxes=False,
vertical_spacing =0.2,)# tune this value until the two charts don't overlap
figg.add_trace(go.Histogram(x=database["race"],name="Race", )
,row=2, col=1)
figg.add_trace(go.Histogram(x=database["imigrante"],name="Immigrant"),row=1, col=2)
figg.add_trace(go.Histogram(x=database["orientacao"],name="Sexual Orientation"),row=1, col=1)
figg.add_trace(go.Histogram(x=database["religiao"],name="Religion"),row=2, col=2)
figg.update_xaxes(title_text="Race", row=2, col=1, )
figg.update_xaxes(title_text="Immigrant", row=1, col=2, )
figg.update_xaxes(title_text="Sexual Orientation", row=1, col=1, )
figg.update_xaxes(title_text="Religion", row=2, col=2, )
figg.show()
figg = make_subplots(
rows=2, cols=2, specs=[[{}, {}], [{"colspan": 2}, None]],
#subplot_titles=("Title 1", "Title 2"),
shared_xaxes=False,
vertical_spacing =0.2,)# tune this value until the two charts don't overlap
figg.add_trace(go.Histogram(x=database["relacionamento"],name="Relationship", )
,row=2, col=1)
figg.add_trace(go.Histogram(x=database["filhos"],name="Children"),row=1, col=2)
figg.add_trace(go.Histogram(x=database["emprego"],name="Job"),row=1, col=1)
figg.update_xaxes(title_text="Job", row=1, col=1, )
figg.update_xaxes(title_text="Children", row=1, col=2, )
figg.update_xaxes(title_text="Relationship", row=2, col=1, )
figg.show()
from plotly import tools
import plotly.offline as py
import plotly.graph_objs as go
trace1 = go.Pie(
labels = database1['ficha'].value_counts().index, values=database1['ficha'].value_counts().values,
domain=dict(x=[0, 0.45], y=[0.55, 1]),
name="Criminal Record",
hoverinfo="label+percent+name", title = 'Criminal Record'
)
trace2 = go.Pie(
labels = database1['fbi'].value_counts().index, values=database1['fbi'].value_counts().values,
domain=dict(x=[0.55, 1.0], y=[0.55, 1]),
name="Known to Police or FBI",
hoverinfo="label+percent+name", title = 'Known to Police or FBI'
)
trace3 = go.Pie(
labels = database1['hate group'].value_counts().index, values=database1['hate group'].value_counts().values,
domain=dict(x=[0, 0.45], y=[0, 0.45]),
name="Known Hate Group or Chat Room Affiliation",
hoverinfo="label+percent+name", title = 'Known Hate Group', titleposition= 'bottom center'
)
trace4 = go.Pie(
labels = database1['alteracao fisica'].value_counts().index, values=database1['alteracao fisica'].value_counts().values,
domain=dict(x=[0.55, 1.0], y=[0, 0.45]),
name="History of Physical Altercations",
hoverinfo="label+percent+name", title = 'History of Physical Altercations', titleposition= 'bottom center',
)
layout = go.Layout(title="Perfis Criminais", width = 960, height = 700, )
data = [trace1, trace2, trace3, trace4]
fig = go.Figure(data=data, layout=layout,)
fig.update_layout(title={
'text': "Criminal and Violent Records",
'y':0.9,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'})
fig.update_layout(legend=dict(title_font_family="Times New Roman",
font=dict(size= 10)))
fig.show()
teste1 = list(database['Part I Crimes'])
palavra1 = str(teste1)
crimes1= ['No evidence', 'Homicide', 'Forcible rape', 'Robbery', 'Aggravated Assault', 'Burglary', 'Larceny-Theft',
'Motor Vehicle Theft', 'Arson']
lista1=[]
for j in range(1,9):
total1 = 0
for i in palavra1:
if i.count(str(j)) == 1:
total1 = total1 + 1
lista1.append([total1, crimes1[j]])
for i in lista1:
print(i)
########################################################################################
teste2 = list(database['Part II Crimes'])
palavra2 = str(teste2)
crimes2= ['No evidence','Simple assault','Fraud, Forgery, Embezzlement', 'Stolen property','Vandalism',
'Weapons offenses', 'Prostitution or other non-rape sex offenses', 'Drugs', 'DUI', 'Other']
lista2=[]
for j in range(1,10):
total2 = 0
for i in palavra2:
if i.count(str(j)) == 1:
total2 = total2 + 1
lista2.append([total2, crimes2[j]])
for i in lista2:
print(i)
[13, 'Homicide'] [11, 'Forcible rape'] [8, 'Robbery'] [18, 'Aggravated Assault'] [10, 'Burglary'] [8, 'Larceny-Theft'] [2, 'Motor Vehicle Theft'] [1, 'Arson'] [47, 'Simple assault'] [3, 'Fraud, Forgery, Embezzlement'] [8, 'Stolen property'] [4, 'Vandalism'] [23, 'Weapons offenses'] [11, 'Prostitution or other non-rape sex offenses'] [17, 'Drugs'] [13, 'DUI'] [62, 'Other']
fig = px.histogram(database1, x = 'Year', y='games', histfunc='count')
fig.show()
fig = px.icicle(database1, path=[px.Constant("all"), 'games', 'praticava bullying', 'sofria bullying'],
title = '| All the data | Violent VideoGames | Used to be the Bully | Used to be Bullied |')
fig.update_layout(margin = dict(t=50, l=51, r=51, b=25))
fig.update_traces(root_color="lightgrey")
fig.show()
fig = figg = make_subplots(
rows=2, cols=2,
#subplot_titles=("Title 1", "Title 2"),
shared_xaxes=False,
vertical_spacing =0.2,)# tune this value until the two charts don't overlap
###################################-------------------##################################-------------------################
figg.add_trace(go.Histogram(y=database["morte parental"],name="Parental Death in Childhood",
## adicionando porcentagem dentro do grafico
text= [str(round(database['morte parental'].value_counts().values[0]/len(database)*100, 2) )+ '%',
str(round(database['morte parental'].value_counts().values[1]/len(database)*100, 2) )+ '%'])
,row=1, col=1)
figg.update_traces(textposition='inside', textfont_size=10)
###################################-------------------##################################-------------------################
figg.add_trace(go.Histogram(y=database["divorcio"],name="Parental Divorce",
text= [str(round(database['divorcio'].value_counts().values[0]/len(database)*100, 2) )+ '%',
str(round(database['divorcio'].value_counts().values[1]/len(database)*100, 2) )+ '%'])
,row=1, col=2)
figg.update_traces(textposition='inside', textfont_size=10)
###################################-------------------##################################-------------------################
figg.add_trace(go.Histogram(y=database["pais solteiros"],name="Raised By Single Parent",
text= [str(round(database['pais solteiros'].value_counts().values[0]/len(database)*100, 2) )+ '%',
str(round(database['pais solteiros'].value_counts().values[1]/len(database)*100, 2) )+ '%'] )
,row=2, col=1)
figg.update_traces(textposition='inside', textfont_size=10)
###################################-------------------##################################-------------------################
figg.add_trace(go.Histogram(y=database["trauma"],name="Childhood Trauma",
text= [str(round(database['trauma'].value_counts().values[1]/len(database)*100, 2) )+ '%',
str(round(database['trauma'].value_counts().values[0]/len(database)*100, 2) )+ '%'])
,row=2, col=2)
figg.update_traces(textposition='inside', textfont_size=10)
###################################-------------------##################################-------------------################
figg.update_xaxes(title_text="Parental Death in Childhood", row=1, col=1, )
figg.update_xaxes(title_text="Parental Divorce", row=1, col=2, )
figg.update_xaxes(title_text="Raised by Single Parent", row=2, col=1, )
figg.update_xaxes(title_text="Childhood Trauma", row=2, col=2, )
figg.show()
fig = make_subplots(
rows=3, cols=3,
specs=[[{"type": "domain"}, {"type": "xy"}, {"type": "domain"}],
[{"colspan": 3}, None, None],
[{"type": "domain"}, {"type": "xy"}, {"type": "domain"}]],
)
#####################################---------------PRIMEIRA LINHA---------############-------------------################
fig.add_trace(go.Pie(labels=database1['abusado fisicamente'].value_counts().index,
values=database1['abusado fisicamente'].value_counts().values,
name="Abuso 1",
hoverinfo="label+percent+name", title = 'Physically Abused', titleposition= 'bottom center'),
row=1, col=1)
fig.add_trace(go.Histogram(x=database["abusado sexualmente"],name="Sexually Abused",
marker=dict(color="orchid"),
text= [str(round(database['abusado sexualmente'].value_counts().values[0]/len(database)*100, 2) )+ '%',
str(round(database['abusado sexualmente'].value_counts().values[1]/len(database)*100, 2) )+ '%']
), row=1, col=2)
fig.add_trace(go.Pie(labels=database1['emocionalmente abusado'].value_counts().index,
values=database1['emocionalmente abusado'].value_counts().values,
name="Emotionally Abused",
hoverinfo="label+percent+name", title = 'Emotionally Abused', titleposition= 'bottom center'),
row=1, col=3)
#####################################---------------SEGUNDA LINHA---------############-------------------################
fig.add_trace(go.Histogram(x=database["socioeconomico"],name="Childhood socioeconomic status",
marker=dict(color="springgreen"),
## adicionando porcentagem dentro do grafico
text= [str(round(database['socioeconomico'].value_counts().values[0]/len(database)*100, 2) )+ '%',
str(round(database['socioeconomico'].value_counts().values[1]/len(database)*100, 2) )+ '%',
str(round(database['socioeconomico'].value_counts().values[2]/len(database)*100, 2) )+ '%',
str(round(database['socioeconomico'].value_counts().values[3]/len(database)*100, 2) )+ '%']
), row=2, col=1)
#####################################---------------TERCEIRA LINHA---------############-------------------################
fig.add_trace(go.Pie(labels=database1['mae sofria violencia'].value_counts().index,
values=database1['mae sofria violencia'].value_counts().values,
name="Mother was violently treated",
hoverinfo="label+percent+name", title = 'Mother was violently treated', titleposition= 'bottom center'),
row=3, col=1)
fig.add_trace(go.Histogram(x=database["abuso substancia"],name="Parent substance abuse",
marker=dict(color="orchid"),
## adicionando porcentagem dentro do grafico
text= [str(round(database['abuso substancia'].value_counts().values[0]/len(database)*100, 2) )+ '%',
str(round(database['abuso substancia'].value_counts().values[1]/len(database)*100, 2) )+ '%']
), row=3, col=2)
fig.add_trace(go.Pie(labels=database1['ficha pais'].value_counts().index,
values=database1['ficha pais'].value_counts().values,
name="Parent criminal record",
hoverinfo="label+percent+name", title = 'Parent criminal record', titleposition= 'bottom center'),
row=3, col=3)
fig.update_layout(height=700, showlegend=True)
fig.show()